#!/usr/bin/env bash

APP=nerdctl

[ -d /opt/$APP ] || mkdir /opt/$APP
cd /opt/$APP


cat > /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter

curl -o  /etc/yum.repos.d/docker-ce.repo   https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

dnf install -y containerd.io-${CONTAINERD_VERSION} --allowerasing

## 生成配置文件
containerd config default > /etc/containerd/config.toml
sed -i 's#sandbox_image.*#sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.6"#' /etc/containerd/config.toml
## 配置 cgroup 驱动程序 systemd
sed -i 's#SystemdCgroup.*#SystemdCgroup = true#' /etc/containerd/config.toml
sed -i 's#config_path = ""#config_path = "/etc/containerd/certs.d"' /etc/containerd/config.toml

source <(curl -sL https://gitee.com/bigbigwood/infra/raw/master/k8s/containerd/containerd-registry.sh)

#systemctl enable containerd && systemctl start containerd
systemctl enable --now containerd.service

ctr version
runc -version

crictl config runtime-endpoint unix:///var/run/containerd/containerd.sock
